$("#btn-login-action").click(function()
		{
			$.ajax({                                                
			type: "POST",                                 
			url: "/login/",  
			data: {"username":$("#input-username").val(),"password":$("#input-password").val()},  
			dataType: "json",
			success: function(msg){         
			}});

		});
$("#input-item-info").bind(" keydown keyup",function(){

	$.ajax({                                                
		type: "POST",                                 
		url: "/Supermarket/salePro.action",
		data:{"itemNo":$("#input-item-info").val(),"method:searchItemByNo":"true"},
		dataType:"json",	
		success:function(msg){
			//console.log(msg)
			if(msg.name){
				$("#show-item-detail").html("");
			//console.log(msg.name);
				$("<div></div>")
				.html("<p>商品名:<b>"+msg.name+"</b></p>"+
						"<p>单价:<b>"+msg.price+"</b></p>"+
						"<p>数量:<input id='item-count'></input></p>"+
						"<a id='btn-addtocart' data-id="+$("#input-item-info").val()+" class='btn btn-primary'>添加</a>"
						).appendTo($("#show-item-detail"));
				$("#btn-addtocart").click(function(){
					$("<tr><td>"+$("#input-item-info").val()+"</td>"+
						"<td>"+msg.name+"</td>"+
						"<td>"+msg.name+"</td>"+
						"<td>"+msg.price+"</td>"+
						"<td>"+$("#item-count").val()+"</td></tr>").appendTo($("#tab-cart-detail>tbody"));
				$("#cart-total").html(parseInt($("#cart-total").html())+msg.price*$("#item-count").val());
				});
			}
			else
				{
				$("#show-item-detail").html("");
				}
		}
		});
});
$("#cart-submit").click(function()
		{
	var $QueryString="";
	var $table = $("#tab-cart-detail tr");
	for($i=1;$i<$table.length;$i++)
		{
		  	var $tr = $($table[$i]);
		    var $tdAry = $tr.find("td");
		   
		    $QueryString+=$($tdAry[0]).html()+","+$($tdAry[4]).html()+",";		  	
		}
	console.log($QueryString);
	///*
		$.ajax({                                                
			type: "POST",                                 
			url: "/Supermarket/salePro.action",
			data:{"questString":$QueryString,"method:SaleByCart":"true"},
			dataType:"json",
			success:function(msg)
			{
				if(msg=="true")
					{
						$("#show-item-detail").html("");
						$("#tab-cart-detail>tbody").html("");
						$("#notice").html("");
						$('<div class="alert alert-success">出货成功！</div>').prependTo($("#notice"))

					}
				}
			});
			//*/
		});
$("#item-fresh").click(function()
		{
				if($("#input-item-no").val()=="")return false;
				$.ajax({                                                
				type: "POST",                                 
				url: "/Supermarket/purchasePro.action",
				data:{"item.itemNo":$("#input-item-no").val()},
				dataType:"json",	
				success:function(msg){
					if(msg=="false")
						{
							$("#input-item-no").attr("disabled","disabled");
							$("#tb-item-detail").css("display","block");
							$("#item-fresh").hide();
							$("#btn-item-submit").show();
						}
					else
						{
							$("#input-item-no").attr("disabled","disabled");
							$("#item-fresh").hide();
							$("#form-input-detail").css("display","block");
						}
				}
			});
		});
$("#btn-item-detail-submit").click(function()
{
	$.ajax({
		type:"POST",
		url:"/Supermarket/purchasePro.action",
		data:{"purchase.itemNo":$("#input-item-no").val(),
			   "purchase.productionDate":$("#input-item-productionDate").val(),
				"purchase.expiredDate":$("#input-item-expiredDate").val(),
				"purchase.num":$("#input-item-num").val(),
				"method:addPurchase":$("#btn-item-detail-submit").attr("value")},
		dataType:"json",
		success:function(msg){
			$('<div class="alert alert-success">添加成功！</div>').prependTo($("#form-item"))
			}
	});
});
$("#btn-item-submit").click(function(){
			$.ajax({
				type:"POST",
				url:"/Supermarket/purchasePro.action",
				data:{"item.itemNo":$("#input-item-no").val(),
							"item.name":$("#input-item-name").val(),
							"item.price":$("#input-item-prive").val(),
							"item.brand":$("#input-item-brand").val(),
							"item.factory":$("#input-item-factory").val(),
							"item.adress":$("#input-item-address").val(),
							"item.tel":$("#input-item-tel").val(),
							"item.employeeId":$("#input-item-employee").val(),
							"method:addItem":$("#btn-item-submit").attr("value")
									},
				dataType:"json",
				success:function(msg){ 
					if(msg=="true")
						{
							$("#tb-item-detail").css("display","none");
							$("#btn-item-submit").hide();
							$("#form-input-detail").css("display","block");
						}else
							{
								$('<div class="alert alert-error">输入错误，请重新输入！</div>').prependTo($("#form-item"))
							}
				}
				
			});
		});
$(document).ready(function(){
	$(".dropdown-toggle").dropdown();
	$("#myModal").modal({backdrop:true,show:false});
	$("#btn-login").click(function(){
		$('#myModal').modal('toggle');
	});

	var hash = window.location.hash;
	if(hash=="#login")
	{
			$('#myModal').modal('toggle');
	}
});
